import 'package:hi_common/util/color.dart';
import 'package:flutter/material.dart';

import '../provider/theme_provider.dart';

class HiBarrageWidget extends StatefulWidget {
  final VoidCallback onClick;
  final String content;
  final bool initStatus;
  final ValueChanged<bool> onToggle;

  const HiBarrageWidget(
      {super.key,
      required this.initStatus,
      required this.onClick,
      required this.content,
      required this.onToggle});

  @override
  State<StatefulWidget> createState() {
    return _HiBarrageWidgetState();
  }
}

class _HiBarrageWidgetState extends State<HiBarrageWidget> {
  //展开
  bool _expand = false;

  @override
  void initState() {
    super.initState();
    _expand = widget.initStatus;
  }

  @override
  Widget build(BuildContext context) {
    return Container(
        decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(15),
            border: Border.all(
                width: 1,
                color:
                    isDarkTheme(context) ? Colors.white : Colors.grey[350]!)),
        child: Padding(
          padding:
              const EdgeInsets.only(left: 10, right: 10, top: 1, bottom: 1),
          child: _buildBtn(),
        ));
  }

  _buildBtn() {
    if (_expand) {
      return _buildExpand();
    } else {
      return _buildCollapse();
    }
  }

  _buildCollapse() {
    return InkWell(
      onTap: () {
        setState(() {
          _expand = true;
        });
        widget.onToggle(true);
      },
      child: const Icon(
        Icons.live_tv_outlined,
        color: Colors.grey,
      ),
    );
  }

  _buildExpand() {
    return Row(
      children: [
        InkWell(
          onTap: () {
            widget.onClick.call();
          },
          child: Text(
            widget.content,
            style: TextStyle(
                fontSize: 10,
                color: isDarkTheme(context) ? Colors.white : Colors.grey),
          ),
        ),
        const SizedBox(
          width: 10,
        ),
        InkWell(
          onTap: () {
            setState(() {
              _expand = false;
            });
            widget.onToggle(false);
          },
          child: const Icon(
            Icons.live_tv_outlined,
            color: primary,
          ),
        )
      ],
    );
  }
}
